package cn.wolfcode.web.controller;


import cn.wolfcode.domain.MessageBoardZrh;
import cn.wolfcode.domain.SystemDictionaryItem;
import cn.wolfcode.qo.SystemDictionaryItemQueryObject;
import cn.wolfcode.service.IMessageBoardZrhService;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.service.ISystemDictionaryItemService;
import cn.wolfcode.util.RequiredPermission;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/message")
public class MessageBoardZrhController {

    @Autowired
    private IMessageBoardZrhService messageBoardZrhService;
    @Autowired
    private ISystemDictionaryItemService systemDictionaryItemService;

    @RequiredPermission(name="留言板页面",expression="message:list")
    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") QueryObject qo){
        //查询业务大类,并传到前台
        List<SystemDictionaryItem> systemDictionaryItems = systemDictionaryItemService.selectSystemDictionaryItemBySn("business");
        model.addAttribute("systemDictionaryItems",systemDictionaryItems);
        //分页查询面板列表
        PageInfo<MessageBoardZrh> pageInfo = messageBoardZrhService.query(qo);
        model.addAttribute("pageInfo", pageInfo);
        return "message/list";
    }

    @RequestMapping("/selectCategoryItem")
    @ResponseBody
    public List<SystemDictionaryItem> selectCategoryItem(SystemDictionaryItemQueryObject qo){
        PageInfo<SystemDictionaryItem> query = systemDictionaryItemService.query(qo);
        return query.getList();
    }




    @RequiredPermission(name="留言板新增/编辑",expression="message:saveOrUpdate")
    @RequestMapping("/saveOrUpdate")
    public String saveOrUpdate(MessageBoardZrh messageBoardZrh) {
        if (messageBoardZrh.getId() == null) {
            messageBoardZrhService.save(messageBoardZrh);
        } else {
            messageBoardZrhService.update(messageBoardZrh);
        }
        return "redirect:/message/list";
    }


}
